#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <fstream>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lineEdit->setEchoMode(QLineEdit::Password);
    ui->lineEdit->setPlaceholderText("请输入密码");

    ui->comboBox_chip->addItem("zhongshu");
    ui->comboBox_chip->addItem("xiaoshu");
    ui->comboBox_chip->addItem("dashu");

    ui->comboBox_drinks->addItem("kele");
    ui->comboBox_drinks->addItem("chengzhi");
    ui->comboBox_drinks->addItem("niunai");

    ui->comboBox_hamberger->addItem("xianglajituibao");
    ui->comboBox_hamberger->addItem("juwuba");
    ui->comboBox_hamberger->addItem("shuangchengbao");

    std::ifstream ifs("C:\\Users\\86157\\Desktop\\config.txt");
    if (!ifs.is_open()) {
        qDebug() << "打开失败";
        return;
    }
    std::string line;
    while (std::getline(ifs, line)) {
        ui->comboBox->addItem(QString::fromStdString(line));
    }

    ifs.close();
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_checkBox_toggled(bool checked)
{
    if (checked)
        ui->lineEdit->setEchoMode(QLineEdit::Normal);
    else
        ui->lineEdit->setEchoMode(QLineEdit::Password);

}

void Widget::on_textEdit_copyAvailable(bool b)
{
    qDebug() << "copyAvailable" << b;
}

void Widget::on_textEdit_cursorPositionChanged()
{
    QTextCursor cursor = ui->textEdit->textCursor();
    qDebug() << "cursorPositionChanged: " << cursor.position();
}

void Widget::on_textEdit_textChanged()
{
    const QString& text = ui->textEdit->toPlainText();
    ui->label->setText(text);
}

void Widget::on_textEdit_undoAvailable(bool b)
{
    qDebug() << "undoAvailable: " << b;
}

void Widget::on_textEdit_redoAvailable(bool b)
{
    qDebug() << "redoAvailable: " << b;
}

void Widget::on_textEdit_selectionChanged()
{
    QTextCursor cursor = ui->textEdit->textCursor();
    qDebug() << "selectionChanged: " << cursor.selectedText();
}

void Widget::on_pushButton_clicked()
{
    qDebug() << ui->comboBox_hamberger->currentText() << ", "
             << ui->comboBox_drinks->currentText() << ", "
             << ui->comboBox_chip->currentText();
}
